/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package FormController;

import Service.SOSService;
import Util.ServiceResponseObject;
import Util.TranslatorUtils;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.web.servlet.ModelAndView;
import th.co.tac.esv.pre.web.util.conf.LogUtil;
import th.co.tac.happy.ejb.sos.data.SosResponse;

/**
 *
 * @author Peat
 */
public class SOSFormController extends BaseFormController {

    public SOSFormController() {
        super("SOSController.properties",
                LogUtil.SosWebLogger,
                LogUtil.SosWebTrnsLogger);
    }

    protected ModelAndView SOS_Console(
            ModelAndView mv, HttpServletRequest request,
            HttpServletResponse response)
            throws NamingException, JSONException {

        SOSService service = new SOSService();
        JSONObject result = new JSONObject();
        String action = request.getParameter("action");
        SosResponse sRes = null;

        if (action.equals("canusesos")) {
            sRes = service.canUseSOS(request);
        }

        if (sRes!=null) {
            result.put("result", true);
            // 0 OK, -1 SERVER ERROR, -2 BL ERROR
            ServiceResponseObject sro = new ServiceResponseObject(
                    sRes.getStatusCode(), "", "", "" + sRes.getErrTxdCode(),
                    sRes.getErrTxdEng(), sRes.getErrTxdTha(), sRes);

            mv.addObject("result", result.toString());
        }
        return mv;
    }
}